<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function jsonp(add) {
            //返回一个promise
            return new Promise((resolve, reject) => {
                // 创建script标签
                var script = document.createElement('script');

                // 解决缓存问题
                var f = add.url.indexOf('?') > - 1 ? '&' : '?';
                add.url += f + '_=' + Date.now();

                //  把参数拼接到url上面
                for (var i in add.params) {
                    add.url += '&' + i + '=' + add.params[i];
                };

                script.src = add.url;
                document.body.appendChild(script);
            })
        }

        function getBaiduParams(data) {
            console.log(data);
        };

        jsonp({
            url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',
            params: {
                //wd: 搜索关键字, cb: 后台约定的回调函数名称
                wd: "美女",
                cb: "getBaiduParams"
            }
        }).then(result => {
            console.log('result ==> ', result);
        });

    </script>
</body>

</html>